package controller.menus;

import gui.menus.MenuLevelActions;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

import javax.swing.JMenuItem;

public class NextLevelMenuItemController implements ActionListener,
		PropertyChangeListener {

	private final JMenuItem nextItem;
	private MenuLevelActions actionHandler;

	public NextLevelMenuItemController(JMenuItem nextItem,
			MenuLevelActions actionHandler) {
		this.nextItem = nextItem;
		this.actionHandler = actionHandler;
		this.actionHandler.addCurrentLevelPropertyChangeListener(this);
		this.nextItem.setEnabled(actionHandler.canNextLevel());
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		this.actionHandler.actionNextLevel();
	}

	/**
	 * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
	 */
	@Override
	public void propertyChange(PropertyChangeEvent evt) {
		this.nextItem.setEnabled(actionHandler.canNextLevel());
	}

}
